Enabling APIs
This lesson provides a brief introduction to GCP service APIs.
We'll cover the following
In GCP, every service is available as an API. Some APIs are enabled by default when we create a project. We need to enable the API to use the rest of the services.
You can expect one to two questions based on enabling API and API explorer in the Associate Cloud Engineer certification exam.
Let’s start with API Dashboard.
API dashboard#
To open the API dashboard, go to Main Menu > API & Services > Dashboard.
Scroll down, and you will see already-enabled APIs. The API dashboard has five sub-menus. We are only interested in the first one, Dashboard and library, for now. The remaining are used for developing Oauth pages for apps built on top of GCP APIs. This is outside the scope of this exam; however, you can explore the options.
Dashboard#
This provides a quick view of the enabled APIs and some usage metrics for the APIs for different periods. The interesting part is that you can try any API without writing a single line of code using API explorer. I am highlighting the API explorer because it is important to remember.
-
Scroll down and click on Cloud Storage API.
-
Under “Tutorials and documentation”, click on Learn more. This will open a new window.
-
A new tab of API reference documentation will open.
-
Under “Resource types”, click on buckets and click on the
insertmethod.
This will open up the documentation for the insert method, and a “try this API” explorer will appear on the right-hand side.
The mandatory parameters are highlighted with the solid red line at the start of the input field. Enter the project ID in the project input and click on the fullscreen icon.
-
Provide the project name, and in the request body, provide a unique name for the bucket. For example,
{ "name": "globally-unique-name-educative" }. You may use a different, globally unique name. -
Click the EXECUTE button. This will ask for some Oauth app permissions from your account.
- If you receive 200 in response then the bucket is created. If not, then the bucket name might be not unique. You can try again with a unique bucket name.
You can verify whether the bucket is created in the cloud storage dashboard. To open up cloud storage dashboard, open Menu > Storage > Dashboard.
API library#
The API library is the bundle of all the APIs available by Google Cloud, including your Gmail, Maps, and other SAAS services.
Open the API library under API & Services. Scroll down, and you will see all the APIs listed here. You can try different APIs the same way we did in the above section.
In the exam, you will be asked questions about the error message you will receive if an API is not enabled and how to resolve it. So, let’s check that out.
Accessing disabled API service#
We will use the most straightforward demonstration for this demo. We will try to use Google Cloud ML API to list ML jobs.
- Open cloud shell.
- Type
gcloud ml-engine jobs list
The command will prompt to authorize this call and then ask you to enable the API first by giving you the prompt there itself.
But after authorizing the call, if you get the following error.
ERROR: (gcloud.ml-engine.jobs.list) You do not currently have an active account selected.
Please run:
$ gcloud auth login
to obtain new credentials.
If you have already logged in with a different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
Then, type gcloud config set account [email]. An email will be used to sign up for the GCP platform.
gcpcourseeducative@cloudshell:~ (gcp-headstart-educative-308308)$ gcloud config set account gcpcourseeducative@gmail.com
Updated property [core/account].
Once the account is set, you can run the command to list ML jobs. Type, gcloud ml-engine jobs list.
gcpcourseeducative@cloudshell:~ (gcp-headstart-educative-308308)$ gcloud ml-engine jobs list
WARNING: The `gcloud ml-engine` commands have been renamed and will soon be removed. Please use `gcloud ai-platform` instead.
API [ml.googleapis.com] not enabled on project [392120076017]. Would
you like to enable and retry (this will take a few minutes)? (y/N)? y
Enabling service [ml.googleapis.com] on project [392120076017]...
Operation "operations/acf.p2-392120076017-16e18b5b-f87a-43a3-bb92-68950137c9f0" finished successfully.
Listed 0 items.
gcpcourseeducative@cloudshell:~ (gcp-headstart-educative-308308)$
You will see Listed 0 items. in the output. As currently, no jobs are running.
You can play around with API explorer and try different APIs. The next step after you understand API explorer is to understand the audit logging in GCP. Because when more than one user is associated with the project, we might want to know who did what just for the record.
Next, look at provisioning Stackdriver workspaces.
Now, Stackdriver is known as Cloud Operations. Stackdriver is a single destination for all operations like logging, monitoring debugging, tracing, etc.
IAM: Hands-On
Stackdriver Workspaces (Cloud Operations)